﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Windows.Forms;

using FreeFlow.Administration;

namespace FreeFlowAdministrator
{
  public class EventLogAdaptor : Adaptor, IRefreshable
  {
    private FreeFlow.Administration.EventLog log;
    public EventLogAdaptor(FreeFlow.Administration.EventLog log)
    {
      this.log = log;
    }

    public override string Text
    {
      get 
      {
        return "Event Log @ " + Environment.MachineName;
      }
    }

    public override object Object
    {
      get 
      { 
        return null; 
      }
    }

    public override Control GetRenderer()
    {
      EventLogControl control = new EventLogControl();
      control.LoadEventLog(log);
      control.RefreshRequired += new EventHandler(TriggerRefreshRequired);
      return control;
    }

    public override void AddChildren(TreeNode node)
    {
      foreach(EventLogEntry entry in log)
      {
        TreeNode childNode = TreeNodeFactory.CreateTreeNode(new EventLogEntryAdaptor(entry));
        node.Nodes.Add(childNode);
      }
    }

    public override int ImageIndex
    {
      get
      {
        return 11;
      }
    }

    #region IRefreshable Members

    public void Refresh()
    {
      log.Refresh();
    }

    #endregion
  }
}
